package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250703080440CreateShortVideoTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250703080440CreateShortVideoTable) Signature() string {
	return "20250703080440_create_short_video_table"
}

// Up Run the migrations.
func (r *M20250703080440CreateShortVideoTable) Up() error {
	if !facades.Schema().HasTable("short_video") {
		return facades.Schema().Create("short_video", func(table schema.Blueprint) {
			table.ID()
			table.String("source").Nullable().Comment("来源")
			table.String("source_id").Nullable().Comment("来源ID")
			table.Integer("category_id").Default(0).Comment("分类ID")
			table.String("title").Comment("名称")
			table.String("cover").Nullable().Comment("封面")
			table.String("remark").Nullable().Comment("描述")
			table.String("author").Nullable().Comment("作者")
			table.Integer("duration").Default(0).Comment("时长")
			table.String("play_url").Nullable().Comment("播放地址")
			table.String("tags").Nullable().Comment("标签")
			table.String("selling_points").Nullable().Comment("看点")
			table.TinyInteger("is_vertical").Default(0).Comment("是否为竖屏")
			table.TinyInteger("status").Default(0).Comment("状态")
			table.DateTime("incoming_time").Nullable().Comment("入库时间")
			table.DateTime("show_time").Nullable().Comment("上架时间")
			table.DateTime("copyright_expiry").Nullable().Comment("版权有效期")
			table.TimestampsTz()

			table.Index("source", "category_id", "title")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250703080440CreateShortVideoTable) Down() error {
	return facades.Schema().DropIfExists("short_video")
}
